package service.demo;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;


public class ServiceEntity extends Service {

	@Override
	public void onCreate() {
		super.onCreate();
		
		Log.v("ServiceEntity", "ServiceEntity -> onCreate()");
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		
		Log.v("ServiceEntity", "ServiceEntity -> onDestroy()");
	}

	@Override
	public IBinder onBind(Intent arg0) {
		Log.v("ServiceEntity", "ServiceEntity -> onBind()");
		
		//要想实现绑定操作，必须返回一个实现了IBinder接口类型的实例，该接口描述了与远程对象进行交互的抽象协议，
		//有了它我们才能与服务进行交互。
		//return new Binder() {};  
		
		//2. 在ServiceEntity类的onBind() 方法中返回一个自定义BinderEntity实例.
		return new BinderEntity();
	}

	@Override
	public boolean onUnbind(Intent intent) {
		Log.v("ServiceEntity", "ServiceEntity -> onUnbind()");
		
		return super.onUnbind(intent);
	}

	@Override
	public void onStart(Intent intent, int startId) {

		super.onStart(intent, startId);
		
		Log.v("ServiceEntity", "ServiceEntity -> onStart()");
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		Log.v("ServiceEntity", "ServiceEntity -> onStartCommand()");
		return super.onStartCommand(intent, flags, startId);
	}

    
	//1. 自定义的Binder类和方法(BinderEntity 内部类)。
    class BinderEntity extends Binder {
    	public void printName(String name) {
    		Log.v("BinderEntity", "printName() : " + name);
    	}
    }
}
